package com.atguigu.lease.common.minio;

import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

/**
 * @author:高尚
 * @data:2025/7/8 14:52
 * @description: 将minioClient加入到ioc容器
 */
/*
/*
  自己的配置类，误被springboot导入了！如何排除！
    1. 少了配置类核心参数，我们就添加参数 【一定使用配置类】
    2. 可以排除配置类，不让他生效 [一定不用]
        @SpringBootApplication(exclude = DataSourceAutoConfiguration.class) [springboot的自动配置类]
        自己的配置类：@ComponentScan(excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = MinioConfiguration.class))
    3. 可能用 满足我们配置minio的参数就会使用
        @ConditionalOnProperty(prefix = "minio", name = "username") 配置里有minio 下有username
 */

@Configuration
@EnableConfigurationProperties(MinioProperties.class)
@ConditionalOnProperty(prefix = "minio", name = "username")
public class MinioConfiguration {
    @Autowired
    private MinioProperties minioProperties;
    @Bean
    public MinioClient minioClient(){
        return MinioClient.builder().endpoint(minioProperties.getEndPoint())
                .credentials(minioProperties.getUsername(), minioProperties.getPassword())
                .build();
    }
}
